]>
Commit | Line | Data |
---|---|---|
98f09799 RBR |
1 | /* |
2 | Copyright (C) 2024 Rubén Beltrán del Río | |
3 | ||
4 | This program is free software: you can redistribute it and/or modify | |
5 | it under the terms of the GNU General Public License as published by | |
6 | the Free Software Foundation, either version 3 of the License, or | |
7 | (at your option) any later version. | |
8 | ||
9 | This program is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | GNU General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU General Public License | |
15 | along with this program. If not, see https://map.tranquil.systems. | |
16 | */ | |
fdb4633d | 17 | import Patterns |
e2c37ac1 | 18 | import SwiftUI |
fdb4633d RBR |
19 | |
20 | struct MapStages: View { | |
21 | ||
22 | let mapSize: CGSize | |
23 | let lineWidth: CGFloat | |
24 | let stages: [CGFloat] | |
25 | let opacity = 0.1 | |
26 | ||
27 | var body: some View { | |
28 | ZStack(alignment: .topLeading) { | |
e2c37ac1 RBR |
29 | PatternView( |
30 | design: .constant(.stitch), pixelSize: 1.0, foregroundColor: .map.stageForeground, | |
31 | backgroundColor: .map.stageBackground | |
32 | ) | |
33 | .frame(width: w(stages[0]), height: mapSize.height) | |
34 | PatternView( | |
35 | design: .constant(.shingles), pixelSize: 1.0, foregroundColor: .map.stageForeground, | |
36 | backgroundColor: .map.stageBackground | |
37 | ) | |
38 | .offset(CGSize(width: w(stages[0]), height: 0)) | |
39 | .frame(width: w(stages[1]) - w(stages[0]), height: mapSize.height) | |
40 | PatternView( | |
41 | design: .constant(.shadowGrid), pixelSize: 1.0, foregroundColor: .map.stageForeground, | |
42 | backgroundColor: .map.stageBackground | |
43 | ) | |
44 | .offset(CGSize(width: w(stages[1]), height: 0)) | |
45 | .frame(width: w(stages[2]) - w(stages[1]), height: mapSize.height) | |
46 | PatternView( | |
47 | design: .constant(.wicker), pixelSize: 1.0, foregroundColor: .map.stageForeground, | |
48 | backgroundColor: .map.stageBackground | |
49 | ) | |
50 | .offset(CGSize(width: w(stages[2]), height: 0)) | |
51 | .frame(width: mapSize.width - w(stages[2]), height: mapSize.height) | |
fdb4633d RBR |
52 | |
53 | Path { path in | |
54 | path.move(to: CGPoint(x: w(stages[0]), y: 0)) | |
55 | path.addLine(to: CGPoint(x: w(stages[0]), y: mapSize.height)) | |
56 | path.closeSubpath() | |
57 | path.move(to: CGPoint(x: w(stages[1]), y: 0)) | |
58 | path.addLine(to: CGPoint(x: w(stages[1]), y: mapSize.height)) | |
59 | path.closeSubpath() | |
60 | path.move(to: CGPoint(x: w(stages[2]), y: 0)) | |
61 | path.addLine(to: CGPoint(x: w(stages[2]), y: mapSize.height)) | |
62 | path.closeSubpath() | |
63 | path.move(to: CGPoint(x: w(stages[0]), y: 0)) | |
64 | path.closeSubpath() | |
e2c37ac1 RBR |
65 | }.strokedPath(StrokeStyle(lineWidth: lineWidth / 4, dash: [10.0, 18.0])).stroke( |
66 | Color.map.axisColor) | |
fdb4633d RBR |
67 | } |
68 | } | |
69 | ||
70 | func w(_ dimension: CGFloat) -> CGFloat { | |
71 | max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0)) | |
72 | } | |
73 | } | |
74 | ||
e2c37ac1 RBR |
75 | #Preview { |
76 | MapStages( | |
77 | mapSize: CGSize(width: 200.0, height: 200.0), lineWidth: CGFloat(0.5), | |
78 | stages: [25.0, 50.0, 75.0]) | |
fdb4633d | 79 | } |